<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { getUrl,ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userIdCacheKey:'hr-train-trainteacher-userid-cache',
				relevantAbilityIdCacheKey:'hr-train-trainteacher-relevantabilityid-cache'
			})
		},
		methods:{
			onSelectAdjustType(data){
				let _that = this
				if(data.code == '37357'){
					_that.$refs.autoform.clear("title1","userId")
					_that.$refs.autoform.clear("title1","sexCode")
					_that.$refs.autoform.clear("title1","postId")
					_that.$refs.autoform.clear("title1","instId")
					_that.$refs.autoform.clear("title1","eduName")
					_that.$refs.autoform.clear("title1","relevantAbilityIdStr")
					_that.om.request(
						'trainTeacher/getUserFlag',
						{
							'adjustTypeId': data.id
						}
					).then(res=>{
						_that.$refs.autoform.changeEditor('title1', 'userId', {
							link: "../../public/pageSearch/pageSearch",
							"linkParam": {
								other: JSON.stringify({
									userIds: res.value.value
								}),
								searchfield: 'q',
								initload:true,
								namefield: "username",
								extrafield: 'instName',
								method:'post',
								url: "orgInstPosUserOfficeView/findUserlistByRequest",
								cachename: _that.userIdCacheKey,
								placeholder: "请输入姓名"
							}
						})
					})
					
				}else{
					_that.$refs.autoform.changeEditor('title1', 'userId',{
						"link":'../../public/searchUser/searchUser',
						"linkParam": {
							cachename: _that.userIdCacheKey,
							isSingle:true,
							isNew:true
						}
					})
					// _that.$refs.autoform.changeEditor('title1', 'userId', {
					// 	link: "../../public/pageSearch/pageSearch",
					// 	"linkParam": {
					// 		other: JSON.stringify({
					// 			userIds: ''
					// 		}),
					// 		searchfield: 'q',
					// 		namefield: "username",
					// 		extrafield: 'instName',
					// 		url: "orgInstPosUserOfficeView/findUserlistByRequest",
					// 		cachename: _that.userIdCacheKey,
					// 		placeholder: "请输入姓名"
					// 	}
					// }, null, _that.autoformdata)
				}
			},
			clearAdjustType(){
				this.$refs.autoform.clear("title1","adjustTypeId")
				this.$refs.autoform.clear("title1","userId")
				this.$refs.autoform.clear("title1","sexName")
				this.$refs.autoform.clear("title1","postName")
				this.$refs.autoform.clear("title1","instName")
				this.$refs.autoform.clear("title1","eduName")
				this.$refs.autoform.clear("title1","relevantAbilityIdStr")
			},
			clearUser(){
				this.$refs.autoform.clear("title1","userId")
				this.$refs.autoform.clear("title1","sexName")
				this.$refs.autoform.clear("title1","postName")
				this.$refs.autoform.clear("title1","instName")
				this.$refs.autoform.clear("title1","eduName")
				this.$refs.autoform.clear("title1","relevantAbilityIdStr")
			},
			initLoad(){
				let _that = this
				let pro1 = _that.om.request('dictZero/getListByCode', { code: "36868" });
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title1", "adjustTypeId", "data", configSelectData(res[0],"id","dicname"))
					_that.$refs.autoform.initSelectIndex("title1", "adjustTypeId")
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: _that.userIdCacheKey,
					success: function(res) {
						if(res.data){
							let d = (res.data[0] || res.data)
							var formdata  = _that.$refs.autoform.formdata
							_that.om.request('/trainTeacher/verifyTeacher', {
								adjustTypeId: formdata.adjustTypeId,
								uerId: d.id,
								trainTeacherId: ''
							}).then(res => {
								if(res.succeed == true){
									formdata.userId = d.id
									formdata.userName = d.username
									formdata.sexCode = res.value.sexCode
									formdata.sexName = res.value.sexName
									formdata.postId = res.value.postId
									formdata.postName = res.value.postName
									formdata.instId = res.value.instId
									formdata.instName = res.value.instName
									formdata.eduId = res.value.eduId
									formdata.eduName = res.value.eduName
								}else{
									_that.$refs.autoform.clear("title1","userId")
									_that.$refs.autoform.clear("title1","sexName")
									_that.$refs.autoform.clear("title1","postName")
									_that.$refs.autoform.clear("title1","instName")
									_that.$refs.autoform.clear("title1","eduName")
									_that.$refs.autoform.clear("title1","relevantAbilityIdStr")
									_that.om.toast(res.msg);
								}
							})
							uni.removeStorage({
								key: _that.userIdCacheKey
							});
						}
					}
				});
				uni.getStorage({
					key: _that.relevantAbilityIdCacheKey,
					success: function(res) {
						let d = res.data
						var formdata  = _that.$refs.autoform.formdata
						formdata.relevantAbilityIdStr = d.map(e=>e.id).join(",")
						formdata.relevantAbilityNameStr = d.map(e=>e.text).join(",");
						_that.$refs.autoform.changeEditor("title1","relevantAbilityIdStr",{
							initSelect:d
						})
						uni.removeStorage({
							key: _that.relevantAbilityIdCacheKey
						});
					}
				});
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
								_that.initLoad()

								let adjustTypeIdEdit = ''
								if(e.edit){
									adjustTypeIdEdit = _that.formdata.adjustTypeId
								}
								changeEditor('title1', 'userId', {
									link: "../../public/pageSearch/pageSearch",
									"linkParam": {
										other: JSON.stringify({
											firstUserId: _that.userId,
											adjustTypeId: adjustTypeIdEdit,
										}),
										searchfield: 'q',
										namefield: "joinUserPost",
										extrafield: 'instName',
										url: "trainTeacher/loadDataGrid",
										cachename: _that.userIdCacheKey,
										placeholder: "请输入姓名"
									}
								}, null, _that.autoformdata)
								
								changeEditor("title1","relevantAbilityIdStr",{
									link:"../../public/multiSearch/multiSearch",
									"linkParam": {
										other:JSON.stringify({
											code: "35905"
										}),
										namefield:'text',
										searchfield:"q",
										initload:true,
										url:'tsysdict/findLastChildTree',
										cachename:_that.relevantAbilityIdCacheKey
									}
								},null,_that.autoformdata)
								
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
